<?php
// +--------------------------------------------------------------------------
// | ZAIYOUDAO [ 载攸道 先顺得常 ] <http://www.zaiyoudao.com>
// +--------------------------------------------------------------------------
// | Copyright © 2009-2016 载攸道 版权所有 <TEL:17090888854>
// +--------------------------------------------------------------------------
// | Project: YiPHP [ 我会的仅仅是偷懒！ ] <http://www.yiphp.com>
// +--------------------------------------------------------------------------
// | Author: 牛很多戒很多不戒 <n@isdce.com> <http://juexue.wang>
// +--------------------------------------------------------------------------

/**
 * Mall
 */
namespace Mall\Controller;
use Common\Controller\AdminController;

/**
 * 商品管理
 */
class OrderController extends AdminController{
	
	/**
	 * 文章管理
	 */
    public function Manage(){

		common_public()->assign_page('商品管理');
		
		$m_mall_content = M('mall_content');
		$m_mall_order = M('mall_order');
		$m_common_user = M('common_user');
		
		
		//搜索指定合作伙伴ID的订单
		$partner_id = I('param.partner_id');
		if($partner_id){
			
			$map['partner_id'] = $partner_id;

		}
		$this->assign('partner_id',$partner_id);
		
		
		//搜索指定用户的订单
		$uid = I('param.uid');
		if($uid){
			$map['uid'] = $uid;
		}
		$this->assign('uid',$uid);
		
		
		//模糊搜索电话订单
		$tel = I('param.tel');
		if($tel){
	
			$map['tel'] = array('like',"%$tel%");

		}
		$this->assign('tel',$tel);
		
		//模糊搜索订单号
		$order_id = I('param.order_id');
		if($order_id){
			
			$map['order_id'] = array('like',"%$order_id%");


		}
		$this->assign('order_id',$order_id);
		

		
		
		//上传开始结束时间
		$down_money = I('param.down_money');
		$top_money = I('param.top_money');
		if($down_money != null and $top_money != null){
			
			$map['money']  = array(array('egt',$down_money),array('elt',$top_money),'and'); 
			
			$this->assign('down_money',$down_money);
			$this->assign('top_money',$top_money);
		}
		
		//开始结束时间
		$begin_time = strtotime(I('param.begin_time'));
		$end_time = strtotime(I('param.end_time'));
		if($begin_time != null and $end_time != null){
			
			$map['time']  = array(array('egt',$begin_time),array('elt',$end_time),'and'); 
			
		}else{
			
			$begin_time=time()-2592000;
			$end_time=time()+86400;
		}
		
		
		$this->assign('begin_time',$begin_time);
		$this->assign('end_time',$end_time);
		
		
		//判断搜索订单类型
		$status = I('param.status');
		if($status!=0){
			
			$map['status'] = $status;

		}else{
			
			$map['status'] = array('neq',0);
		
			
		}
		$this->assign('status',$status);
		
		//判断搜索订单类型
		$pay_type = I('param.pay_type');
		if($pay_type!=0){
			
			$map['pay_type'] = $pay_type;

		}else{
			
			$map['pay_type'] = array('neq',0);
		
			
		}
		$this->assign('pay_type',$pay_type);
		
		$express_type = I('param.express_type');
		if($express_type){
			
			$map['express_type'] = $express_type;

		}else if($express_type=='0'){
			
			$map['express_type'] = 0;

			
		}else{
			
		}
		$this->assign('express_type',$express_type);
		
		
		
		
		$map['form_order_id'] = 0;
		$map['order_type'] = get_mall_order_conf('MALL_ORDER_TYPE_GOODS');
		
		
		$list = $m_mall_order->where($map)->order('time desc')->page($_GET['p'].',50')->select();
	
		$count      = $m_mall_order->where($map)->count();// 查询满足要求的总记录数
		$Page       = new \Think\Page($count,50);// 实例化分页类 传入总记录数和每页显示的记录数
		$show       = $Page->show();// 分页显示输出
		$this->assign('pages',$show);
		//查询关联信息
		foreach($list as $i=>$k){
			
			$fmap['id'] = $list[$i]['form_id'];
			$fdata = $m_mall_content->where($fmap)->find();
			$umap['id'] = $list[$i]['uid'];
			
			$udata = $m_common_user->where($umap)->find();
			
			
			$list[$i]['channel'] = $fdata['name'];
			$list[$i]['nickname'] = $udata['nickname'];
			$list[$i]['n_img'] = $udata['img'];
			
			
			$partner_map['id'] = $list[$i]['partner_id'];
			
			$partner_data = $m_common_user->where($partner_map)->find();
			
		
			$list[$i]['partner_nickname'] = $partner_data['nickname'];
			$list[$i]['partner_img'] = $partner_data['img'];
			
		
		}
		//赋值
		$this->assign('list',$list);
		$this->assign('data',$data);
		$this->assign('form_id',$fmap['id']);
		
		$classify = $this->getChannel();
		
		
		$this->assign('classify',$classify);
		$this->assign('classifys',$classify);
		
		
		$this->display();
	}
	
	/**
	 * 获得分类
	 */
	public function getChannel(){
		
			$m_mall_content = M('mall_content');
		
			//获得顶级分类
			$map['form_id'] = 0;
			$map['type'] = get_mall_model_conf('MALL_CLASSIFY');
			$map['status'] = 1;
			
			$list = $m_mall_content->where($map)->order('sort desc')->select();
			
			//获得下级分类即商品数量
			foreach($list as $i=>$k){
				
				$down_map['form_id'] = $list[$i]['id'];
				$down_map['type'] = get_mall_model_conf('MALL_CLASSIFY');
				$down_map['status']  =1;
				$down_list = $m_mall_content->where($down_map)->order('sort desc')->select();
				
				$list[$i]['down'] = $down_list;
				
			}
		
	
			return $list;
	}
	
	/**
	 * 新增文章
	 */
	public function Create(){
		

		$m_mall_content = M('mall_content');
			
		//判断是否是ajax请求
		if(IS_POST){

			
			//获得数据
			$data = I();
			
			$data['value'] = I('param.value','','');
			$data['uid'] = getUID();
			$data['form_id'] =  I('param.form_id')?I('param.form_id'):0;;
			$data['type'] = get_mall_model_conf('MALL_GOODS');;
			$data['time'] = time;
			$data['ip'] = get_client_ip();
			$data['status'] = 1;
			
			$result = $m_mall_content->add($data);
			
			if($result){    //设置成功后跳转页面的地址，默认的返回页面是$_SERVER['HTTP_REFERER'] 
			
				$this->success('新增成功', U('Mall/Goods/Manage'));
			
			} else {    //错误页面的默认跳转页面是返回前一页，通常不需要设置  
			
				$this->error('新增失败');
			
			}
		
				
		}else{
			
			
				$classify = $this->getChannel();
		
			
	
				$this->assign('list',$classify);
		
				$this->display();
		}
		
	
	}
	
	/**
	 * 详情
	 */
	public function Detail(){
    
		$m_mall_order = M('mall_order');
		$m_mall_content = M('mall_content');
		$m_common_user = M('common_user');
		#订单详情
		$map['id'] = I('param.id');
		$map['status'] = array('in','1,2,3');
		$data = $m_mall_order->where($map)->find();
		
		#商品详情
		$goods_map['id'] = $data['goods_id'];
		$goods_data = $m_mall_content->where($goods_map)->find();
		
		#买家详情
		$user_map['id'] = $data['uid'];
		$user_data = $m_common_user->where($user_map)->find();
		
		$this->assign('data',$data);
		$this->assign('user_data',$user_data);
		$this->display();
		
		
	
	}
	/**
	 * 编辑文章
	 */
	public function Edit(){
    
		$m_mall_content = M('mall_content');
		
		$map['id'] = I('param.id');
		//判断是否是ajax请求
		if(IS_POST){

			
			set_mall_draft($map['id']); //保存草稿
			
			$data = I('');
			unset($data['id']);
			$data['value'] = I('param.value','','');
			$data['time'] = time();
			
			$data['ip'] = get_client_ip();
			
			$result = $m_mall_content->where($map)->save($data);
			
			if($result){    //设置成功后跳转页面的地址，默认的返回页面是$_SERVER['HTTP_REFERER'] 
			
				$this->success('编辑成功', U('Mall/Goods/Manage'));
			
			} else {    //错误页面的默认跳转页面是返回前一页，通常不需要设置  
			
				$this->error('编辑失败');
			
			}
		
		}else{
			
			$map['type'] = get_mall_model_conf('MALL_GOODS');
			$map['status'] = array('in','1,2,3');
		
		
			$data = $m_mall_content->where($map)->find();
			
			$this->assign('data',$data);
		
			$classify = $this->getChannel();
		

			$this->assign('list',$classify);
				
			$this->display();
		}
		
	
	}
	
	/**
	 * 批量改变状态
	 */
	public function Delete($id,$status=0){
		//判断是否是ajax请求
		if(IS_AJAX){
			$m_mall_content = M('mall_content');
			$id = $id?$id:I('param.id');
			$status = $status?$status:I('param.status');
			
			if($id){
				$id = explode(',',$id);
				foreach($id as $i=>$k){
					$map['id'] = $id[$i];
					$data['status'] = $status;
					$m_mall_content->where($map)->save($data);
				}
				//返回信息
				$info = get_errcode(0);
			}else{
				$info = get_errcode(10000001);
			}
		}
		//返回信息		
		$info = $info?$info:get_errcode(-2);
		$this->ajaxReturn($info);
	}
	
	
	/**
	 * 专辑订单
	 */
    public function Music_order(){
		$m_mall_order = M("mall_order");
		$m_mall_content = M("mall_content");
		$m_common_user = M("common_user");
		
		
		//搜索指定用户的订单
		$uid = I('param.uid');
		if($uid){
			$order_map['uid'] = $uid;
		}
		$this->assign('uid',$uid);
		
		//模糊搜索订单号
		$order_id = I('param.order_id');
		if($order_id){
			$order_map['order_id'] = array('like',"%$order_id%");
		}
		$this->assign('order_id',$order_id);
		
		//上传开始结束时间
		$down_money = I('param.down_money');
		$top_money = I('param.top_money');
		if($down_money != null and $top_money != null){
			$order_map['money']  = array(array('egt',$down_money),array('elt',$top_money),'and');
			$this->assign('down_money',$down_money);
			$this->assign('top_money',$top_money);
		}
		
		//开始结束时间
		$begin_time = strtotime(I('param.begin_time'));
		$end_time = strtotime(I('param.end_time'));
		if($begin_time != null and $end_time != null){
			$order_map['time']  = array(array('egt',$begin_time),array('elt',$end_time),'and'); 
		}else{
			$begin_time=time()-2592000;
			$end_time=time()+86400;
		}
		
		$this->assign('begin_time',$begin_time);
		$this->assign('end_time',$end_time);
		
		$map['uid'] = getUID();
		$map['status'] = 1;
		$map['type'] = array("in",'22,16,19');
		$list = $m_mall_content->where($map)->field("id")->select();
		
		$list = array_column($list,'id');
		$list = array_unique($list);
		$list_str = implode(',',$list);
		
		$order_map['goods_id'] = array("in",$list_str);
		$order_map['status'] = 1;
		$_GET['p'] = $_GET['p']?$_GET['p']:1;
		$order_list = $m_mall_order->where($order_map)->order("time desc")->page($_GET['p'],20)->select();
		$count      = $m_mall_order->where($order_map)->count();// 查询满足要求的总记录数
		$Page       = new \Think\Page($count,50);// 实例化分页类 传入总记录数和每页显示的记录数
		$show       = $Page->show();// 分页显示输出
		
		foreach($order_list as $i=>$v){
			$user_map['id'] = $order_list[$i]['uid'];
			$user_data = $m_common_user->where($user_map)->find();
			$order_list[$i]['n_img'] = $user_data['img'];
			#专辑
			$goods_map['id'] = $order_list[$i]['goods_id'];
			$goods_name = $m_mall_content->where($goods_map)->find();
			
			$order_list[$i]['goods_name'] = $goods_name['name'];
			
		}
		$this->assign('pages',$show);
		$this->assign('list',$order_list);
		$this->display();
	}
	
	/**
	 * 专辑订单
	 */
    public function all_music_order(){
		$m_mall_order = M("mall_order");
		$m_mall_content = M("mall_content");
		$m_common_user = M("common_user");
		
		
		//搜索指定用户的订单
		$uid = I('param.uid');
		if($uid){
			$order_map['uid'] = $uid;
		}
		$this->assign('uid',$uid);
		
		//模糊搜索订单号
		$order_id = I('param.order_id');
		if($order_id){
			$order_map['order_id'] = array('like',"%$order_id%");
		}
		$this->assign('order_id',$order_id);
		
		//上传开始结束时间
		$down_money = I('param.down_money');
		$top_money = I('param.top_money');
		if($down_money != null and $top_money != null){
			$order_map['money']  = array(array('egt',$down_money),array('elt',$top_money),'and');
			$this->assign('down_money',$down_money);
			$this->assign('top_money',$top_money);
		}
		
		//开始结束时间
		$begin_time = strtotime(I('param.begin_time'));
		$end_time = strtotime(I('param.end_time'));
		if($begin_time != null and $end_time != null){
			$order_map['time']  = array(array('egt',$begin_time),array('elt',$end_time),'and'); 
		}else{
			$begin_time=time()-2592000;
			$end_time=time()+86400;
		}
		
		$this->assign('begin_time',$begin_time);
		$this->assign('end_time',$end_time);
		
		#$map['uid'] = getUID();
		$map['status'] = 1;
		$map['type'] = array("in",'22,16,19');
		$list = $m_mall_content->where($map)->field("id")->select();
		
		$list = array_column($list,'id');
		$list = array_unique($list);
		$list_str = implode(',',$list);
		
		$order_map['goods_id'] = array("in",$list_str);
		$order_map['status'] = 1;
		$_GET['p'] = $_GET['p']?$_GET['p']:1;
		$order_list = $m_mall_order->where($order_map)->order("time desc")->page($_GET['p'],20)->select();
		$count      = $m_mall_order->where($order_map)->count();// 查询满足要求的总记录数
		$Page       = new \Think\Page($count,50);// 实例化分页类 传入总记录数和每页显示的记录数
		$show       = $Page->show();// 分页显示输出
		
		foreach($order_list as $i=>$v){
			$user_map['id'] = $order_list[$i]['uid'];
			$user_data = $m_common_user->where($user_map)->find();
			$order_list[$i]['n_img'] = $user_data['img'];
			#专辑
			$goods_map['id'] = $order_list[$i]['goods_id'];
			$goods_name = $m_mall_content->where($goods_map)->find();
			
			$order_list[$i]['goods_name'] = $goods_name['name'];
			
		}
		$this->assign('pages',$show);
		$this->assign('list',$order_list);
		$this->display();
	}
	
	
	/**
	 * 专辑订单
	 */
    public function tixian_order(){
		$m_mall_order = M("mall_order");
		$m_mall_content = M("mall_content");
		$m_common_user = M("common_user");
		
		//搜索指定用户的订单
		$uid = I('param.uid');
		if($uid){
			$order_map['uid'] = $uid;
		}
		$this->assign('uid',$uid);
		
		//模糊搜索订单号
		$order_id = I('param.order_id');
		if($order_id){
			$order_map['order_id'] = array('like',"%$order_id%");
		}
		$this->assign('order_id',$order_id);
		
		//开始结束时间
		$begin_time = strtotime(I('param.begin_time'));
		$end_time = strtotime(I('param.end_time'));
		if($begin_time != null and $end_time != null){
			$order_map['time']  = array(array('egt',$begin_time),array('elt',$end_time),'and'); 
		}else{
			$begin_time=time()-2592000;
			$end_time=time()+86400;
		}
		
		$this->assign('begin_time',$begin_time);
		$this->assign('end_time',$end_time);
		
		
		$order_map['order_type'] = 5;
		$order_map['status'] = array("in","1,2");
		$_GET['p'] = $_GET['p']?$_GET['p']:1;
		$order_list = $m_mall_order->where($order_map)->order("time desc")->page($_GET['p'],20)->select();
		$count      = $m_mall_order->where($order_map)->count();// 查询满足要求的总记录数
		$Page       = new \Think\Page($count,50);// 实例化分页类 传入总记录数和每页显示的记录数
		$show       = $Page->show();// 分页显示输出
		
		foreach($order_list as $i=>$v){
			$user_map['id'] = $order_list[$i]['uid'];
			$user_data = $m_common_user->where($user_map)->find();
			$order_list[$i]['n_img'] = $user_data['img'];
			
		}
		$this->assign('pages',$show);
		$this->assign('list',$order_list);
		$this->display();
	}
	/**
	 * 专辑订单
	 */
    public function tixian_order_s(){
		$m_mall_order = M("mall_order");
		$m_mall_content = M("mall_content");
		$m_common_user = M("common_user");
		
		//搜索指定用户的订单
		$uid = I('param.uid');
		if($uid){
			$order_map['uid'] = $uid;
		}
		$this->assign('uid',$uid);
		
		//模糊搜索订单号
		$order_id = I('param.order_id');
		if($order_id){
			$order_map['order_id'] = array('like',"%$order_id%");
		}
		$this->assign('order_id',$order_id);
		
		//开始结束时间
		$begin_time = strtotime(I('param.begin_time'));
		$end_time = strtotime(I('param.end_time'));
		if($begin_time != null and $end_time != null){
			$order_map['time']  = array(array('egt',$begin_time),array('elt',$end_time),'and'); 
		}else{
			$begin_time=time()-2592000;
			$end_time=time()+86400;
		}
		
		$this->assign('begin_time',$begin_time);
		$this->assign('end_time',$end_time);
		
		
		$order_map['order_type'] = 5;
		$order_map['status'] = array("in","2");
		$_GET['p'] = $_GET['p']?$_GET['p']:1;
		$order_list = $m_mall_order->where($order_map)->order("time desc")->page($_GET['p'],20)->select();
		$count      = $m_mall_order->where($order_map)->count();// 查询满足要求的总记录数
		$Page       = new \Think\Page($count,50);// 实例化分页类 传入总记录数和每页显示的记录数
		$show       = $Page->show();// 分页显示输出
		
		foreach($order_list as $i=>$v){
			$user_map['id'] = $order_list[$i]['uid'];
			$user_data = $m_common_user->where($user_map)->find();
			$order_list[$i]['n_img'] = $user_data['img'];
			
		}
		$this->assign('pages',$show);
		$this->assign('list',$order_list);
		$this->display();
	}
	
	
	/**
	 * 批量改变状态
	 */
	public function tixian_zhifu($id,$status=0){
		//判断是否是ajax请求
		if(IS_AJAX){
			$m_mall_order = M('mall_order');
			$id = $id?$id:I('param.id');
			$status = $status?$status:I('param.status');
			
			if($id){
				$id = explode(',',$id);
				foreach($id as $i=>$k){
					$map['id'] = $id[$i];
					$data['status'] = $status;
					$m_mall_order->where($map)->save($data);
				}
				//返回信息
				$info = get_errcode(0);
			}else{
				$info = get_errcode(10000001);
			}
		}
		//返回信息		
		$info = $info?$info:get_errcode(-2);
		$this->ajaxReturn($info);
	}
	
	
	
	
	#用户流水
	public function money_order(){
		$m_mall_order = M("mall_order");
		$m_mall_content = M("mall_content");
		$m_common_user = M("common_user");
		$m_mall_money = M("mall_money");
		
		//搜索指定用户的订单
		$uid = I('param.uid');
		if($uid){
			$money_map['uid'] = $uid;
		}
		$this->assign('uid',$uid);
		
		//模糊搜索订单号
		$order_id = I('param.order_id');
		if($order_id){
			$money_map['order_id'] = array('like',"%$order_id%");
		}
		$this->assign('order_id',$order_id);
		
		//开始结束时间
		$begin_time = strtotime(I('param.begin_time'));
		$end_time = strtotime(I('param.end_time'));
		if($begin_time != null and $end_time != null){
			$money_map['time']  = array(array('egt',$begin_time),array('elt',$end_time),'and');
		}else{
			
			$begin_time=time()-2592000;
			$end_time=time()+86400;
		}
		$this->assign('begin_time',$begin_time);
		$this->assign('end_time',$end_time);
		
		$money_map['status'] = 1;
		$_GET['p'] = $_GET['p']?$_GET['p']:1;
		$money_list = $m_mall_money->where($money_map)->order("time desc")->page($_GET['p'],20)->select();
		
		$count      = $m_mall_money->where($money_map)->count();// 查询满足要求的总记录数
		$Page       = new \Think\Page($count,50);// 实例化分页类 传入总记录数和每页显示的记录数
		$show       = $Page->show();// 分页显示输出
		foreach($money_list as $i=>$v){
			$user_map['id'] = $money_list[$i]['uid'];
			$user_data = $m_common_user->where($user_map)->find();
			$money_list[$i]['n_img'] = $user_data['img'];
			$money_list[$i]['nickname'] = $user_data['nickname'];
		}
		$this->assign('pages',$show);
		$this->assign('list',$money_list);
		$this->display();
	}
	
	#导出用户流水
	public function money_order_daochu(){
		$m_mall_order = M("mall_order");
		$m_mall_content = M("mall_content");
		$m_common_user = M("common_user");
		$m_mall_money = M("mall_money");
		
		//搜索指定用户的订单
		$uid = I('param.uid');
		if($uid){
			$money_map['uid'] = $uid;
		}
		$this->assign('uid',$uid);
		
		//模糊搜索订单号
		$order_id = I('param.order_id');
		if($order_id){
			$money_map['order_id'] = array('like',"%$order_id%");
		}
		$this->assign('order_id',$order_id);
		
		//开始结束时间
		$begin_time = strtotime(I('param.begin_time'));
		$end_time = strtotime(I('param.end_time'));
		if($begin_time != null and $end_time != null){
			$money_map['time']  = array(array('egt',$begin_time),array('elt',$end_time),'and');
		}else{
			
			$begin_time=time()-2592000;
			$end_time=time()+86400;
		}
		$this->assign('begin_time',$begin_time);
		$this->assign('end_time',$end_time);
		
		$money_map['status'] = 1;
		$_GET['p'] = $_GET['p']?$_GET['p']:1;
		$money_list = $m_mall_money->where($money_map)->order("time desc")->select();
		
		foreach($money_list as $i=>$v){
			$user_map['id'] = $money_list[$i]['uid'];
			$user_data = $m_common_user->where($user_map)->find();
			$money_list[$i]['n_img'] = $user_data['img'];
			
			$money_list[$i]['nickname'] = $user_data['nickname']."-".$user_data['id'];
			if($money_list[$i]['order_type'] == 1){
				$money_list[$i]['order_type_name'] = "支付宝";
			}else if($money_list[$i]['order_type'] == 2){
				$money_list[$i]['order_type_name'] = "微信";
			}else if($money_list[$i]['order_type'] == 3){
				$money_list[$i]['order_type_name'] = "余额";
			}
			if($money_list[$i]['type'] == 1){
				$money_list[$i]['type_name'] = "收入";
			}else if($money_list[$i]['order_type'] == 2){
				$money_list[$i]['type_name'] = "支出";
			}
			$money_list[$i]['order_id'] = $money_list[$i]['value'].' ';
		}
		
		$xlsName  = "订单记录";
       $xlsCell  = array(
            array('time','下单时间'),
            array('order_id','订单号'),
            array('nickname','昵称-uid'),
			array('type_name','收入/支出'),
            array('order_type_name','支付方式'),
            array('money','支付方式'),
            array('begin_money','变更前'),
            array('money','变更金额'),
            array('end_money','变更后'),
        );
		$this->exportExcel($xlsName,$xlsCell,$money_list);
	}
	
	
	#用户流水详情
	public function money_order_detail(){
		$m_mall_order = M("mall_order");
		$m_mall_content = M("mall_content");
		$m_common_user = M("common_user");
		$m_mall_money = M("mall_money");
		$m_mall_order = M('mall_order');
		$m_mall_content = M('mall_content');
		$m_common_user = M('common_user');
		#订单详情
		$map['order_id'] = I('param.order_id');
		$map['status'] = array('in','1,2,3');
		$data = $m_mall_order->where($map)->find();
		
		#商品详情
		$goods_map['id'] = $data['goods_id'];
		$goods_data = $m_mall_content->where($goods_map)->find();
		
		#买家详情
		$user_map['id'] = $data['uid'];
		$user_data = $m_common_user->where($user_map)->find();
		
		#卖家昵称
		$users_map['id'] = $goods_data['uid'];
		$users_data = $m_common_user->where($users_map)->find();
		
		$this->assign('data',$data);
		$this->assign('user_data',$user_data);
		$this->assign('users_data',$users_data);
		$this->display();
		
	}
	
	
	#管理员导出账单
	public function all_daochu(){
		$m_mall_order = M("mall_order");
		$m_mall_content = M("mall_content");
		$m_common_user = M("common_user");
		
		//搜索指定用户的订单
		$uid = I('param.uid');
		if($uid){
			$order_map['uid'] = $uid;
		}
		$this->assign('uid',$uid);
		
		//模糊搜索订单号
		$order_id = I('param.order_id');
		if($order_id){
			$order_map['order_id'] = array('like',"%$order_id%");
		}
		$this->assign('order_id',$order_id);
		
		//上传开始结束时间
		$down_money = I('param.down_money');
		$top_money = I('param.top_money');
		if($down_money != null and $top_money != null){
			$order_map['money']  = array(array('egt',$down_money),array('elt',$top_money),'and');
			$this->assign('down_money',$down_money);
			$this->assign('top_money',$top_money);
		}
		
		//开始结束时间
		$begin_time = strtotime(I('param.begin_time'));
		$end_time = strtotime(I('param.end_time'));
		if($begin_time != null and $end_time != null){
			$order_map['time']  = array(array('egt',$begin_time),array('elt',$end_time),'and'); 
		}else{
			$begin_time=time()-2592000;
			$end_time=time()+86400;
		}
		
		$this->assign('begin_time',$begin_time);
		$this->assign('end_time',$end_time);
		
		#$map['uid'] = getUID();
		$map['status'] = 1;
		$map['type'] = array("in",'22,16,19');
		$list = $m_mall_content->where($map)->field("id")->select();
		
		$list = array_column($list,'id');
		$list = array_unique($list);
		$list_str = implode(',',$list);
		
		$order_map['goods_id'] = array("in",$list_str);
		$order_map['status'] = 1;
		$_GET['p'] = $_GET['p']?$_GET['p']:1;
		$order_list = $m_mall_order->where($order_map)->order("time desc")->select();
		
		foreach($order_list as $i=>$v){
			$user_map['id'] = $order_list[$i]['uid'];
			$user_data = $m_common_user->where($user_map)->find();
			$order_list[$i]['n_img'] = $user_data['img'];
			$money_list[$i]['nickname'] = $user_data['nickname'];
			#专辑
			$goods_map['id'] = $order_list[$i]['goods_id'];
			$goods_name = $m_mall_content->where($goods_map)->find();
			
			$order_list[$i]['order_id'] = $order_list[$i]['order_id'].' ';
			$order_list[$i]['goods_name'] = $goods_name['name'];
			$order_list[$i]['time'] = date("Y-m-d H:i",$order_list[$i]['time']);
			$order_list[$i]['nickname'] = $user_data['nickname']."-".$user_data['id'];
			
			if($order_list[$i]['pay_type'] == 1){
				$order_list[$i]['zhifu'] = '支付宝';
			}else if($order_list[$i]['pay_type'] == 2){
				$order_list[$i]['zhifu'] = '微信';
			}else if($order_list[$i]['pay_type'] == 3){
				$order_list[$i]['zhifu'] = '余额';
			}
			
		}
		/* dump($order_list);die; */
		/* exel导出 */
		$xlsName  = "订单记录";
       $xlsCell  = array(
            array('time','下单时间'),
            array('order_id','订单号'),
            array('nickname','昵称-uid'),
            array('goods_name','来源'),
            array('money','金额'),
            array('money','支付方式'),
        );
		$this->exportExcel($xlsName,$xlsCell,$order_list);
      }
	  
	  
	#管理员导出账单
	public function daochu(){
		$m_mall_order = M("mall_order");
		$m_mall_content = M("mall_content");
		$m_common_user = M("common_user");
		
		//搜索指定用户的订单
		$uid = I('param.uid');
		if($uid){
			$order_map['uid'] = $uid;
		}
		$this->assign('uid',$uid);
		
		//模糊搜索订单号
		$order_id = I('param.order_id');
		if($order_id){
			$order_map['order_id'] = array('like',"%$order_id%");
		}
		$this->assign('order_id',$order_id);
		
		//上传开始结束时间
		$down_money = I('param.down_money');
		$top_money = I('param.top_money');
		if($down_money != null and $top_money != null){
			$order_map['money']  = array(array('egt',$down_money),array('elt',$top_money),'and');
			$this->assign('down_money',$down_money);
			$this->assign('top_money',$top_money);
		}
		
		//开始结束时间
		$begin_time = strtotime(I('param.begin_time'));
		$end_time = strtotime(I('param.end_time'));
		if($begin_time != null and $end_time != null){
			$order_map['time']  = array(array('egt',$begin_time),array('elt',$end_time),'and'); 
		}else{
			$begin_time=time()-2592000;
			$end_time=time()+86400;
		}
		
		$this->assign('begin_time',$begin_time);
		$this->assign('end_time',$end_time);
		
		$map['uid'] = getUID();
		$map['status'] = 1;
		$map['type'] = array("in",'22,16,19');
		$list = $m_mall_content->where($map)->field("id")->select();
		
		$list = array_column($list,'id');
		$list = array_unique($list);
		$list_str = implode(',',$list);
		
		$order_map['goods_id'] = array("in",$list_str);
		$order_map['status'] = 1;
		$_GET['p'] = $_GET['p']?$_GET['p']:1;
		$order_list = $m_mall_order->where($order_map)->order("time desc")->select();
		
		foreach($order_list as $i=>$v){
			$user_map['id'] = $order_list[$i]['uid'];
			$user_data = $m_common_user->where($user_map)->find();
			$order_list[$i]['n_img'] = $user_data['img'];
			$money_list[$i]['nickname'] = $user_data['nickname'];
			#专辑
			$goods_map['id'] = $order_list[$i]['goods_id'];
			$goods_name = $m_mall_content->where($goods_map)->find();
			
			$order_list[$i]['order_id'] = $order_list[$i]['order_id'].' ';
			$order_list[$i]['goods_name'] = $goods_name['name'];
			$order_list[$i]['time'] = date("Y-m-d H:i",$order_list[$i]['time']);
			$order_list[$i]['nickname'] = $user_data['nickname']."-".$user_data['id'];
			
			if($order_list[$i]['pay_type'] == 1){
				$order_list[$i]['zhifu'] = '支付宝';
			}else if($order_list[$i]['pay_type'] == 2){
				$order_list[$i]['zhifu'] = '微信';
			}else if($order_list[$i]['pay_type'] == 3){
				$order_list[$i]['zhifu'] = '余额';
			}
			
		}
		
		$xlsName  = "订单记录";
       $xlsCell  = array(
            array('time','下单时间'),
            array('order_id','订单号'),
            array('nickname','昵称-uid'),
            array('goods_name','来源'),
            array('money','金额'),
            array('money','支付方式'),
        );
		$this->exportExcel($xlsName,$xlsCell,$order_list);
      }
	
	public function exportExcel($expTitle,$expCellName,$manual_export){
		
		$m_common_user = M("common_user");
		$d_map['id'] = getUID();
		$d_map['status'] = 1;
		$user_data =  $m_common_user->where($d_map)->find();
        $xlsTitle = iconv('utf-8', 'gb2312', $expTitle);//文件名称
        $fileName = $user_data['nickname'].date("YmdHi",time());//or $xlsTitle 文件名称可根据自己情况设定
        #$fileName = "123";//or $xlsTitle 文件名称可根据自己情况设定
        $cellNum = count($expCellName);
        $dataNum = count($manual_export);
        import("Org.Util.PHPExcel");
        $objPHPExcel = new \PHPExcel();
		
		$objPHPExcel->getActiveSheet()->getDefaultColumnDimension(A)->setWidth(25);
		$objPHPExcel->getActiveSheet()->getStyle('c')->getAlignment()->setWrapText(true);
		$objPHPExcel->getActiveSheet()->getStyle('d')->getAlignment()->setWrapText(true);
		$objPHPExcel->getActiveSheet()->getStyle('e')->getAlignment()->setWrapText(true);
        $cellName = array('A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','AA','AB','AC','AD','AE','AF','AG','AH','AI','AJ','AK','AL','AM','AN','AO','AP','AQ','AR','AS','AT','AU','AV','AW','AX','AY','AZ','BA','BB','BC','BD','BE','BF','BG','BH','BI','BJ','BK','BL','BM','BN','BO','BP','BQ','BR','BS','BT','BU','BV','BW','BX','BY','BZ','CA','CB','CC','CD','CE','CF','CG','CH','CI','CJ','CK','CL','CM','CN');
		
        //$objPHPExcel->getActiveSheet(0)->mergeCells('A1:'.$cellName[$cellNum-1].'1');//合并单元格 
        $objPHPExcel->setActiveSheetIndex(0)->setCellValue('A1');  
        for($i=0;$i<$cellNum;$i++){
            $objPHPExcel->setActiveSheetIndex(0)->setCellValue($cellName[$i].'1', $expCellName[$i][1]); 
        } 
          // Miscellaneous glyphs, UTF-8   
        for($i=0;$i<$dataNum;$i++){
          for($j=0;$j<$cellNum;$j++){
            $objPHPExcel->getActiveSheet(0)->setCellValue($cellName[$j].($i+2), $manual_export[$i][$expCellName[$j][0]]);
          }             
        }
		$objPHPExcel->getActiveSheet()->setTitle("订单记录");  
		$objPHPExcel->createSheet();
		
        import("Org.Util.PHPExcel.IOFactory");
    
        header('pragma:public');
        header('Content-type:application/vnd.ms-excel;charset=utf-8;name="'.$xlsTitle.'.xls"');
        header("Content-Disposition:attachment;filename=$fileName.xls");//attachment新窗口打印inline本窗口打印
        $objWriter = \PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');  
        $objWriter->save('php://output'); 
        exit;   
    }
	
	
}